<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: Admin
  Date: 2022-11-02
  Time: 13:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>生产工序设计单</title>
    <style>
        input {
            border: white;
            border: 0px;
        }

    </style>
</head>
<form id="fileformgxxg">
    <%--    file--%>
<input type="hidden" name="designproceduretag" id="designproceduretaggxsj" >
<input type="hidden" name="id"  value="${param.id}" >

</form>
    <form id="sforms">
    <%--    dp--%>
    <input type="hidden" name="costpricesum" id="costpricesumtable">
    <input type="hidden" name="checktag" value="S001-0">
    <input type="hidden" name="changetag" value="B002-0">
    <input type="hidden" name="designmoduletag" value="G002-0">
    <input type="hidden" name="designmodulechangetag" value="G003-0">
    <input type="hidden" id="firstkindid" name="firstkindid">
    <input type="hidden" id="firstkindname" name="firstkindname">
    <input type="hidden" id="secondkindid" name="secondkindid">
    <input type="hidden" id="secondkindname" name="secondkindname">
    <input type="hidden" id="thirdkindid" name="thirdkindid">
    <input type="hidden" id="thirdkindname" name="thirdkindname">
    <table class="TABLE_STYLE3">
        <tr height=20 class="TR_STYLE1">
            <td class="TD_HANDBOOK_STYLE1">您正在做的业务是：生产管理--产品生产工序设计--制定产品生产工序设计单</td>
        </tr>
    </table>
    <table style="margin-left:865px" class="TABLE_STYLE6">
        <tr height=20 class="TR_STYLE1">
            <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right class="TD_STYLE8">
                <input type="button" value="添加工序" onclick="mcplistcl()" class="btn btn-success">
                <input type="button" onclick="mcplistdel()" value="删除工序" class="btn btn-warning">&nbsp;
                <input type="button" value="提交" id="btnsaves2y" class="btn btn-success">
            </td>
        </tr>
    </table>

    <input name="design_ID" type="hidden">
    <input name="product_ID" type="hidden">
    <div class="DIV_STYLE2">
        <table cellspacing=0 cellpadding=0 width=350 align=center border=0 bgcolor="#FFFFFF">
            <tbody>
            <tr>
                <td valign=bottom align=center class="TABLE_STYLE6" rowspan=2>
                    <table cellspacing=0 cellpadding=0 width="800px" border=0
                           style="BORDER-RIGHT: #333333 1px solid; BORDER-TOP: #333333 1px solid; BORDER-LEFT: #333333 1px solid; BORDER-BOTTOM: #333333 1px solid;">
                        <tbody>
                        <tr>
                            <td colspan="4" height="10">
                                <table width="850px" style="height: 400px">
                                    <tr>
                                        <td>
                                            <table align=center class="TABLE_STYLE4">
                                                <tr height=20 class="TR_STYLE1">
                                                    <td align=center height=5 class="TD_STYLE5">&nbsp;</td>
                                                </tr>
                                            </table>
                                            <table align=center class="TABLE_STYLE4">
                                                <tr height=20 class="TR_STYLE1">
                                                    <td align=center height=5 class="TD_STYLE5"><font size="4"><b>生产工序设计单</b></font>
                                                    </td>
                                                </tr>
                                            </table>
                                            <table align=center class="TABLE_STYLE4">
                                                <tr height=20 class="TR_STYLE1">
                                                    <td align=center height=5 class="TD_STYLE5">&nbsp;</td>
                                                </tr>
                                            </table>
                                            <table align=center class="TABLE_STYLE4">
                                                <tr height=20 class="TR_STYLE1">
                                                    <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right
                                                        class="TD_STYLE8" width="20%">产品名称：
                                                    </td>
                                                    <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="40%">
                                                        <input type="text" name="productname" id="productname" readonly>&nbsp;
                                                    </td>
                                                    <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right
                                                        class="TD_STYLE8" width="15%">产品编号&nbsp;&nbsp;：
                                                    </td>
                                                    <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="40%">
                                                        <input type="text" name="productid" id="productid" readonly>&nbsp;
                                                    </td>
                                                </tr>
                                                <tr height=20 class="TR_STYLE1">
                                                    <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right
                                                        class="TD_STYLE8" width="10%">设计人：
                                                    </td>
                                                    <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="40%">
                                                        <input type="text" name="designer" id="designer"> &nbsp;
                                                    </td>

                                                </tr>
                                            </table>

                                            <table id="detailss" align=center
                                                   class="table table-striped table-bordered table-condensed table-hover">
                                            </table>

                                            <table align=center class="TABLE_STYLE4">
                                                <tr height=20 class="TR_STYLE1">
                                                </tr>
                                            </table>
                                            <TABLE align=center class="TABLE_STYLE4">
                                                <tr height=20 class="TR_STYLE1">
                                                </tr>
                                                <tr height=20 class="TR_STYLE1">
                                                    <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right
                                                        class="TD_STYLE8" width="10%">登记人&nbsp;&nbsp;：
                                                    </td>
                                                    <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="40%">
                                                        <%--                                                       --%>
                                                        <input type="text" name="register" value="${username}"
                                                               id="register">&nbsp;
                                                    </td>
                                                    <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right
                                                        class="TD_STYLE8" width="10%">登记时间：
                                                    </td>
                                                    <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="40%">
                                                        <input type="text" id="registertime" readonly
                                                               name="registertime">&nbsp;
                                                    </td>
                                                </tr>
                                                <tr height=20 class="TR_STYLE1">
                                                    <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right
                                                        class="TD_STYLE8" width="20%">设计要求：
                                                    </td>
                                                    <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="89%"
                                                        colspan="3"><textarea name="proceduredescribe"
                                                                              id="proceduredescribedptable" style="width: 561px; height: 171px;"></textarea>&nbsp;
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3" nowrap width="56">
                            </td>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3" nowrap height="100"></td>
                            <td></td>
                        </tr>

                        <tr valign="bottom">
                            <td colspan="4" nowrap align="center"></td>
                        </tr>
                        </td>
                        <tr>
                            <td colspan="4" nowrap align="right"></td>
                        </tr>
                        </tbody>
                    </table>
                </td>
                <td width=1 bgcolor=#ffffff height=2></td>
                <td width=1 bgcolor=#ffffff height=2></td>
                <td width=1 bgcolor=#ffffff height=2></td>
            </tr>
            <tr>
                <td width=1 bgcolor=#333333 height=120></td>
                <td width=1 bgcolor=#666666 height=120></td>
                <td width=1 bgcolor=#999999 height=120></td>
            </tr>
            <tr valign=top align=right>
                <td colspan=4>
                    <table cellspacing=0 cellpadding=0 align=center class="TABLE_STYLE6" border=0>
                        <tbody>
                        <tr>
                            <td bgcolor=#333333 height=1></td>
                        </tr>
                        <tr>
                            <td bgcolor=#666666 height=1></td>
                        </tr>
                        <tr>
                            <td bgcolor=#999999 height=1></td>
                        </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr valign=center align=right>
                <td colspan=4></td>
            </tr>
            </tbody>
        </table>
    </div>

</form>


<!--外层容器div-->
<div class="modal " id="mcpaddwin" data-backdrop="static">
    <!--对话框容器div-->
    <div class="modal-dialog modal-lg">
        <!--对话框内容容器div-->
        <div class="modal-content">

        </div>
    </div>
</div>

<script>

    //获取制定设计单的信息
    $(function () {
        // 获取当前时间
        var time = getTime();
        $("#registertime").val(time);
        var idgx = '${param.id}'
        $.get("queryfilebyid.action/" + idgx, function (data) {
            console.log(data);
            $("#productid").val(data.productid)
            $("#productname").val(data.productname)
            $("#firstkindid").val(data.firstkindid)
            $("#firstkindname").val(data.firstkindname)
            $("#secondkindid").val(data.secondkindid)
            $("#secondkindname").val(data.secondkindname)
            //快速实现  数据展示
            $("#detailss").bootstrapTable({
                //工序明细
                uniqueId: "procedureid",
                height: 200,
                columns: [
                    {
                        field: '',
                        title: '',
                        checkbox: true,
                    },
                    {
                        field: 'procedurename',
                        title: '工序名称'

                    }

                    , {
                        field: 'procedureid',
                        title: '工序编号'
                    }, {
                        field: 'proceduredescribe',
                        title: '描述'
                    }
                    , {
                        field: 'labourhouramount',
                        title: '工时数',
                        formatter: function (value, row, index) {
                            return "<input type='text' value='" + value + "' onchange='changenum11(this)' >";
                        }
                    },
                    {
                        field: 'amountunit',
                        title: '工时单位',
                        formatter: function (value, row, index) {
                            if (value == "" || value == null) {
                                return "<label class='label label-success'>小时</label>";
                            }

                        }
                    },
                    {
                        field: 'costprice',
                        title: '单位工时成本',
                        formatter: function (value, row, index) {
                            return "<input type='text' value='" + value + "' onchange='changenum22(this)' >";
                        }

                    },
                    {
                        field: 'subtotal',
                        title: '工时成本小计（元）',
                        formatter: function (value, row, index) {
                            return "<input readonly type='text'  value='" + value + "'  >";
                        }

                    }]
            });
        })

    }, "json")


    //显示工序表模态框
    function mcplistcl() {
        $("#mcpaddwin").modal({
            remote: "mcplist.jsp"
        });

        $("#mcpaddwindel").click(function () {
            $("#mcpaddwin").modal("hide")
        })
    }


    //输入数字，将数字更新到表格中changenum11
    function changenum11(obj1) {
        //获取表格当前所有数据
        var arr2 = $("#detailss").bootstrapTable("getData");
        //获取当前输入的值
        var labourhouramount = $(obj1).val();

        //获取当前操作行的id
        var id = $(obj1).parent().parent().find("td:eq(2)").text();
        //循环表格数据  和当前行id比较  相等  跟新labourhouramount
        $(arr2).each(function (index, item) {
            if (item.procedureid == id) {
                item.labourhouramount = labourhouramount;
            }
        })
        //数据加载到表格
        $("#detailss").bootstrapTable("load", arr2);
        // }
    }


    //changenum22
    function changenum22(obj) {
        //获取表格当前所有数据
        var arr2 = $("#detailss").bootstrapTable("getData");
        //获取当前输入的值
        var costprice = $(obj).val();

        //获取当前操作行的id
        var id = $(obj).parent().parent().find("td:eq(2)").text();
        //获取当前操作行的id
        var shu1 = $(obj).parent().parent().find("input:eq(1)").val();

        var reg = /^[0-9]*$/
        if (!reg.test(shu1)) {
            alert("请输入数字")
            $(obj).parent().parent().find("input:eq(1)").val("1");
            return
        }
        var shu2 = $(obj).parent().parent().find("input:eq(2)").val();

        var reg2 = /^[0-9]*$/
        if (!reg2.test(shu2)) {
            alert("请输入数字")
            $(obj).parent().parent().find("input:eq(2)").val("1");
            return
        }

        var zong = Number(shu1) * Number(shu2)

        //循环表格数据  和当前行id比较  相等  costPrice
        $(arr2).each(function (index, item) {
            if (item.procedureid == id) {
                item.costprice = costprice;
                item.subtotal = zong;
            }

        })

        //$("#costpricesumtable").val(sum)
        //数据加载到表格
        $("#detailss").bootstrapTable("load", arr2);
    }


    //保存工序明细表设计
    $("#btnsaves2y").click(function () {
        var arrxu = $("#detailss").bootstrapTable("getData");
        //沒有
        if (arrxu.length == 0) {
            alert("您没有选择工序");
            return false;
        }

        var arr = $("#sforms").serializeArray();
        console.log(arr)
        var gongxushow = {};
        $(arr).each(function (index, item) {
            gongxushow[item.name] = item.value;
        })
        //从表格获取组成明细数据
        var arr2 = $("#detailss").bootstrapTable("getData");
        //将明细数据 存入和实体类中同名的属性上
        gongxushow["detailss"] = arr2;
        $.ajax({
            url: "adddesignProcedureshow.action",
            type: "put",
            data: JSON.stringify(gongxushow),
            contentType: "application/json",
            dataType: "json",
            success: function (data) {
                alert(data.msg)
                var dataobj = $("#fileformgxxg").serializeArray();
                var obj = {};
                $(dataobj).each(function (index, item) {
                    obj[item.name] = item.value;
                })
                if(data.cm==1) {
                    $.ajax({
                        url: "updatefilepojo.action",
                        type: "put",
                        data: JSON.stringify(obj),
                        contentType: "application/json",
                        dataType: "json",
                        success: function (data) {
                        }
                    })
                }

            }
        })
    })

    //批量删除
    function mcplistdel() {
        var arr = $("#detailss").bootstrapTable("getSelections");
        if (arr.length == 0) {
            alert("请至少选择一条记录，批量删除");
            return;
        }
        //假刪
        if(confirm("您确定要删除?")){
        $(arr).each(function (index,item) {
            $("#detailss").bootstrapTable("removeByUniqueId",item.procedureid)
        })
        }

    }


    //添加按下
    function addmcbtn(id) {
        $.get("querymcpbyid.action/" + id, function (data) {
            var arrs = []
            $(data).each(function (index, item) {
                arrs.push({
                    "procedureid": item.typeId, "procedurename": item.typeName
                    , "labourhouramount": "", "costprice": "", "subtotal": "", "proceduredescribe": item.describe1
                })
            })
            //将数据加载到表格中$("#material").bootstrapTable("append",arr);
            var arr2 = $("#detailss").bootstrapTable("getData");
            if (arr2.length == 0) {
                //将数据加载到表格中
                $("#detailss").bootstrapTable("append", arrs);
            } else {
                //循环表格数据  和当前行id比较  相等  跟新num
                var res = false;
                $(arr2).each(function (index, item) {
                    if (item.procedureid == id) {
                        alert("你已添加了此工序")
                        res = true;
                    }
                })
                if (!res) {
                    //将数据加载到表格中
                    $("#detailss").bootstrapTable("append", arrs);
                }
            }

        })
    }


    // 获取当前日期时间方法
    function getTime() {
        var date = new Date();
        var y = date.getFullYear();
        var M = date.getMonth() + 1;
        M = M < 10 ? ('0' + M) : M;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d
        var h = date.getHours();
        var m = date.getMinutes();
        var s = date.getSeconds();
        const time = y + '-' + M + '-' + d + " " + h + ":" + m + ":" + s;
        return time;
    }


</script>
</div>
</body>
</html>
